// action的创建函数
import type { IAction } from "./ActionTypes"
import type { IMovie } from "../../services/MovieService"
import type { ISearchCondition } from "../../services/CommonTypes"

export type saveMovieAction = IAction<'movie_save', {
    movies: IMovie[],
    total: number,
}>

function saveMovieActions(movies: IMovie[], total: number): saveMovieAction {
    return {
        type: "movie_save",
        payload: {
            movies,
            total,
        }
    }
}

export type SetLoadingAction = IAction<'movie_setLoading', boolean>

function setLoadingAction(isLoading: boolean): SetLoadingAction {
    return {
        type: "movie_setLoading",
        payload: isLoading,
    }
}

export type SetConditionAction = IAction<'movie_setCondition', ISearchCondition>

function setConditionAction(condition: ISearchCondition): SetConditionAction {
    return {
        type: "movie_setCondition",
        payload: condition,
    }
}

export type DeleteAction = IAction<'movie_delete', string>
function deleteAction(id: string): DeleteAction {
    return {
        type: "movie_delete",
        payload: id,
    }
}

export default {
    saveMovieActions,
    setLoadingAction,
    setConditionAction,
    deleteAction
}